home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / threads.h < prev    next >
C/C++ Source or Header  |  1998-09-15  |  5KB  |  143 lines

  1. /*
  2.  * @(#)threads.h    1.35 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. #ifndef _THREADS_H_
  16. #define _THREADS_H_
  17.  
  18. #include "oobj.h"
  19. #include "interpreter.h"
  20. #include "timeval.h"
  21. #include "monitor.h"
  22. #include "bool.h"
  23. #include "sys_api.h"
  24.  
  25. #include "java_lang_Thread.h"
  26. #include "java_lang_ThreadGroup.h"
  27.  
  28. #define MinimumPriority        java_lang_Thread_MIN_PRIORITY
  29. #define MaximumPriority        java_lang_Thread_MAX_PRIORITY
  30. #define NormalPriority        java_lang_Thread_NORM_PRIORITY
  31.  
  32. /*
  33.  * Support for thread queue
  34.  */
  35.  
  36. extern sys_mon_t *_queue_lock;
  37.  
  38. #define QUEUE_LOCK_INIT() monitorRegister(_queue_lock, "Thread queue lock")
  39. #define QUEUE_LOCK()      sysMonitorEnter(_queue_lock)
  40. #define QUEUE_LOCKED()      sysMonitorEntered(_queue_lock)
  41. #define QUEUE_UNLOCK()      sysMonitorExit(_queue_lock)
  42. #define QUEUE_NOTIFY()      sysMonitorNotify(_queue_lock)
  43. #define QUEUE_WAIT()      sysMonitorWait(_queue_lock, \
  44.                      SYS_TIMEOUT_INFINITY, FALSE)
  45.  
  46. /*
  47.  * Thread-related data structures
  48.  */
  49.  
  50. typedef struct Hjava_lang_Thread HThread;
  51. typedef struct Hjava_lang_ThreadGroup HThreadGroup;
  52. typedef struct Hjava_lang_Thread *TID;
  53.  
  54. typedef sys_thread_t ThreadPrivate;
  55.  
  56. /* Access to thread data structures */
  57. #define THREAD(tid)    ((struct Classjava_lang_Thread *) unhand(tid))
  58. #define SYSTHREAD(tid)    ((sys_thread_t *)THREAD(tid)->PrivateInfo)
  59.  
  60. #define THR_SYSTEM 0        /* System thread */
  61. #define THR_USER   1        /* User thread */
  62.  
  63. extern int ActiveThreadCount;        /* All threads */
  64. extern int UserThreadCount;        /* User threads */
  65.  
  66. /* The default Java stack size is legitimately platform-independent */
  67. #define JAVASTACKSIZE (400 * 1024)     /* Default size of a thread java stack */
  68.  
  69. extern long ProcStackSize;        /* Actual size of thread C stack */
  70. extern long JavaStackSize;        /* Actual maximum size of java stack */
  71.  
  72. extern stackp_t mainstktop;        /* Base of primordial thread stack */
  73.  
  74. /*
  75.  * External interface to threads support
  76.  */
  77.  
  78. void threadBootstrap(TID tid, stackp_t sb);
  79. int  threadCreate(TID, unsigned int, size_t, void *(*)());
  80. TID  threadSelf(void);
  81. void threadSleep(int);
  82. int  threadEnumerate(TID*, int);
  83.  
  84. void threadDumpInfo(TID, bool_t);        /* Debugging help in debug.c */
  85.  
  86. int threadPostException(TID tid, void *exc);
  87. void threadTryVMSuspend(void);
  88.  
  89. /*
  90.  * There may be certain initialization that can't be done except by the
  91.  * thread on itself, e.g. setting thread-local data in Solaris threads.
  92.  * This function is called from ThreadRT0() when the thread starts up
  93.  * to take care of such things.
  94.  */
  95. #define threadInit(tid, sb)        sysThreadInit(SYSTHREAD(tid), sb)
  96.  
  97. /*
  98.  * Exit the current thread.  This function is not expected to return.
  99.  *
  100.  * Note that we currently never stop a thread dead in its tracks, but
  101.  * rather throw an exception against it that causes it to unwind its
  102.  * stack, exit monitors, etc. and exit in a single place (ThreadRT0).
  103.  * If a thread is caused to exit precipitously by calling threadExit()
  104.  * at random places it will corrupt the runtime and at minimum will
  105.  * fail to clean the thread out of any monitors it currently holds.
  106.  */
  107. #define threadExit()            sysThreadExit()
  108.  
  109. /*
  110.  * Note that we do not check that priorities are within Java's limits down here.
  111.  * In fact, we make use of that for things like the idle and clock threads.
  112.  * This may change once we work out a portable priority model.
  113.  */
  114. #define threadSetPriority(tid, pri)    sysThreadSetPriority(SYSTHREAD(tid), pri)
  115. #define threadGetPriority(tid, prip)    sysThreadGetPriority(SYSTHREAD(tid), prip)
  116.  
  117. #define threadYield()            sysThreadYield()
  118. #define threadResume(tid)        sysThreadResume(SYSTHREAD(tid))
  119. #define threadSuspend(tid)        sysThreadSuspend(SYSTHREAD(tid))
  120.  
  121. /*
  122.  * Return information about this thread's stack.  This is used by
  123.  * Garbage Collection code that needs to inspect the stack.
  124.  *
  125.  * It is permissable to return a null stack_base for those threads
  126.  * that don't have a known stack (e.g. not allocated by the threads
  127.  * package).  It is also permissable to return a somewhat bogus
  128.  * stack_pointer for the current thread.
  129.  */
  130. #define threadStackBase(tid)        sysThreadStackBase(SYSTHREAD(tid))
  131. #define threadStackPointer(tid)        sysThreadStackPointer(SYSTHREAD(tid))
  132.  
  133. #define threadCheckStack()        sysThreadCheckStack()
  134.  
  135. /*
  136.  * Interface to thread interrupt support
  137.  */
  138. #define threadInterrupt(tid)        sysThreadInterrupt(SYSTHREAD(tid))
  139. #define threadIsInterrupted(tid, ClearInterrupted) \
  140.     sysThreadIsInterrupted(SYSTHREAD(tid), ClearInterrupted)
  141.  
  142. #endif /* !_THREADS_H_ */
  143.